"""Definition of the Research Achievement content type
"""

from zope.interface import implements

try:
    from Products.LinguaPlone import public as atp
except ImportError:
    # No multilingual support
    from Products.Archetypes import atapi as atp
from Products.ATContentTypes.content import base
from Products.ATContentTypes.content import schemata

# -*- Message Factory Imported Here -*-
from Products.ATContentTypes.content import newsitem
from garbas.watermark import WatermarkImageField
from my315ok.researchevent.interfaces import IResearchAchievement
from my315ok.researchevent.config import PROJECTNAME
from my315ok.researchevent import researcheventMessageFactory as _
from Products.ATContentTypes import ATCTMessageFactory as _a
from Products.validation.config import validation
from Products.validation.validators.SupplValidators import MaxSizeValidator
from Products.validation import V_REQUIRED
from Products.ATContentTypes.configuration import zconf
validation.register(MaxSizeValidator('checkImageMaxSize',
                                     maxsize=zconf.ATImage.max_file_size))

org = newsitem.ATNewsItemSchema.copy()
org.delField("image")

ResearchAchievementSchema = org + atp.Schema((
                                                                           
atp.TextField(
        'reference',
        default_content_type = 'text/restructured',
        default_output_type = 'text/html',
        searchable = True,
        allowable_content_types=('text/plain', 'text/restructured', 'text/html',),
        storage=atp.AnnotationStorage(),
        
        widget=atp.RichWidget(
            label=_(u"reference"),
            description=_(u"reference"),
        ),
    ),

    # -*- Your Archetypes field definitions here ... -*-
WatermarkImageField(
        name='image',
        
        languageIndependent=True,
        watermark='/demo/pub/logo.png',
        swallowResizeExceptions = zconf.swallowImageResizeExceptions.enable,
        pil_quality = zconf.pil_config.quality,
        pil_resize_algo = zconf.pil_config.resize_algo,
        max_size = zconf.ATImage.max_image_dimension,
        sizes= {'large'   : (768, 768),
                       'preview' : (400, 400),
                       'mini'    : (200, 200),
                       'thumb'   : (128, 128),
                   
                      },
        validators = (('isNonEmptyFile', V_REQUIRED),
                             ('checkImageMaxSize', V_REQUIRED)),
        widget=atp.ImageWidget(
            label= _a(u'label_image', default=u'Image'),
            ),
        original_size=(400, 400),
        ),
))

# Set storage on fields copied from ATContentTypeSchema, making sure
# they work well with the python bridge properties.

ResearchAchievementSchema['title'].storage = atp.AnnotationStorage()
ResearchAchievementSchema['description'].storage = atp.AnnotationStorage()
ResearchAchievementSchema.moveField("reference",before="title")
schemata.finalizeATCTSchema(ResearchAchievementSchema, moveDiscussion=False)


class ResearchAchievement(newsitem.ATNewsItem):
    """a scientific research achievement for research event"""
    implements(IResearchAchievement)

    meta_type = "ResearchAchievement"
    schema = ResearchAchievementSchema

    title = atp.ATFieldProperty('title')
    description = atp.ATFieldProperty('description')

    # -*- Your ATSchema to Python Property Bridges Here ... -*-

atp.registerType(ResearchAchievement, PROJECTNAME)
